package com.ruoyi.system.service.module.estate.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.domain.module.estate.EstateBuild;
import com.ruoyi.system.domain.module.estate.EstateBuildUnit;
import com.ruoyi.system.mapper.module.estate.EstateBuildMapper;
import com.ruoyi.system.mapper.module.estate.EstateBuildUnitMapper;
import com.ruoyi.system.service.module.estate.IEstateBuildService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 楼栋（1级） + 单元（2级） Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-31
 */
@Service
public class EstateBuildServiceImpl extends ServiceImpl<EstateBuildMapper, EstateBuild> implements IEstateBuildService {

	@Resource
	private EstateBuildMapper estateBuildMapper;

	@Resource
	private EstateBuildUnitMapper estateBuildUnitMapper;

	@Override
	public List<EstateBuild> getTreeSelect(int estateId) {
		QueryWrapper<EstateBuild> qw = new QueryWrapper<>();
		qw.eq("estate_id", estateId);
		qw.orderByAsc("sort");
		List<EstateBuild> buildList = estateBuildMapper.selectList(qw);
		if(CollUtil.isNotEmpty(buildList)){
//			for (EstateBuild build : buildList){
//				QueryWrapper<EstateBuildUnit> qwUnit = new QueryWrapper<>();
//				qwUnit.eq("build_id", build.getId());
//				qwUnit.orderByAsc("sort");
//				List<EstateBuildUnit> unitList = estateBuildUnitMapper.selectList(qwUnit);
//				if(CollUtil.isNotEmpty(unitList)){
//					for (EstateBuildUnit unit : unitList){
//						unit.setBuildType(1);
//						unit.setBuildName(unit.getUnitNo());
//					}
//				}
//				build.setChildren(unitList);
//			}
		}
		return buildList;
	}
}
